package com.siteseat.common.deploy;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import com.siteseat.common.foundation.PropertyHelper;
import com.siteseat.common.foundation.ScheduledActor;

/**
 * @author yqiang
 */
public class DeployScheduler extends ScheduledActor {

  private List<Deployer> deployers = new ArrayList<Deployer>();
  
  /**
   * Gets the deployers
   *
   * @return the deployers
   */
  public List<Deployer> getDeployers() {
    return deployers;
  }

  /**
   * Sets the deployers
   *
   * @param deployers the deployers to set
   */
  public void setDeployers( List<Deployer> deployers ) {
    this.deployers = deployers;
  }
  
  /**
   * 
   *
   * @param deployer
   */
  public void addDeployer( Deployer deployer ) {
    getDeployers().add( deployer );
  }
  
  /**
   * 
   *
   * @param deployerCollection
   */
  public void addDeployers( Collection<Deployer> deployerCollection ) {
    getDeployers().addAll( deployerCollection );
  }

  /**
   * {@inheritDoc}
   */
  @Override
  protected void doInit() throws Exception {
    super.doInit();
    
    PropertyHelper.ensureNotNull( log, getDeployers(), "deployers" );
  }

  /**
   * {@inheritDoc}
   */
  @Override
  protected void onScheduled() {
    log.debug( "scheduling" );
    for( Deployer deployer: deployers ) {
      deployer.runDeployment();
    }
  }  
  
}
